/**
 * Class to hold the lists of UI and non-UI resources for a plugin component
 */
jsx3.lang.Class.defineClass("ux.core.util.component.Resources",
        jsx3.lang.Object,
        null,
        function(config) {

            /**
             * {jsx3.util.List} List of {ux.core.util.component.UIResource} objects representing the ui resources for this component
             * @private
             */
            config.prototype.UIResources = null;

            /**
             * {jsx3.util.List} List of {ux.core.util.component.Resource} objects representing the ui resources for this component
             * @private
             */
            config.prototype.otherResources = null;

            /**
             * Constructor for this class.
             *
             * @param entity {jsx3.xml.Entity} an xml node containing the information for the resources of a plugin component
             * @throws {ux.core.exception.InvalidComponentSchemaException} if the xml is invalid
             */
            config.prototype.init = function(entity) {
                this.jsxsuper();
                this.UIResources = new jsx3.util.List(0);
                this.otherResources = new jsx3.util.List(0);
                var children = entity.getChildNodes().iterator();
                while (children.hasNext()) {
                    var child = children.next();
                    var childName = child.getNodeName();
                    if (childName == "ui_resources") {
                        var childUIs = child.getChildNodes().iterator();
                        while (childUIs.hasNext()) {
                            var childUI = childUIs.next();
                            if (childUI.getNodeName() == "ui_resource") {
                                this.UIResources.add(new ux.core.util.component.UIResource(childUI), this.UIResources.size());
                            }
                            else {
                                throw new ux.core.exception.InvalidComponentSchemaException("Unknown tag '" + childUI.getNodeName() + "' in the 'ui_resources' tag of the component schema.  Supported tags are: ui_resource");
                            }
                        }
                        if (this.UIResources.size() == 0) {
                            throw new ux.core.exception.InvalidComponentSchemaException("Tag 'ui_resources' requires at least one 'ui_resource' child tag.")
                        }
                    }
                    else if (childName == "other_resources") {
                        var childReses = child.getChildNodes().iterator();
                        while (childReses.hasNext()) {
                            var childRes = childReses.next();
                            if (childRes.getNodeName() == "resource") {
                                this.otherResources.add(new ux.core.util.component.Resource(childRes), this.otherResources.size());
                            }
                            else {
                                throw new ux.core.exception.InvalidComponentSchemaException("Tag 'other_resources' requires at least one 'resource' child tag.")
                            }
                        }
                        if (this.otherResources.size() == 0) {
                            throw new ux.core.exception.InvalidComponentSchemaException("Tag 'resources' requires at least one of the following child tags: ui_resources, other_resources")
                        }
                    }
                    else {
                        throw new ux.core.exception.InvalidComponentSchemaException("Unknown tag '" + childName + "' in the 'resources' tag of the component schema.  Supported tags are: ui_resources, other_resources");
                    }
                }
                if ((this.UIResources.size() == 0) && (this.otherResources.size() == 0)) {
                    throw new ux.core.exception.InvalidComponentSchemaException("Tag 'resources' requires at least one of the following child tags: ui_resources, other_resources")
                }
            }

            /**
             * Returns an iterator of all of the child UIResource objects.
             *
             * @return {jsx3.util.Iterator} an iterator for all of the child {ux.core.util.component.UIResource} objects.
             */
            config.prototype.getUIResources = function() {
                return this.UIResources.clone().iterator();
            }

           /**
             * Returns a UIResource object .
             * @ParentExtensionPoint {String} The extension_point_id of the component in which plugin component will reside.
             * That component will be a ui_resource defined in a plugin container.
             * @return {ux.core.util.component.UIResource}
             */
            config.prototype.getUIResource = function(ParentExtensionPoint) {
                var iterator = this.UIResources.clone().iterator();
                var uiResource = null;
                var pExtensionpointlist
                var pExtensionpoint
                while (iterator.hasNext()) {
                    uiResource = iterator.next()
                    pExtensionpointlist = uiResource.getParentExtensionPoints();
                    while (pExtensionpointlist.hasNext()) {
                        pExtensionpoint = pExtensionpointlist.next()
                        if (pExtensionpoint == ParentExtensionPoint) {
                            return uiResource
                        }
                    }
                }
                return null;
            }


            /**
             * Returns an iterator of all of the child Resource objects.
             *
             * @return {jsx3.util.Iterator} an iterator for all of the child {ux.core.util.component.Resource} objects.
             */
            config.prototype.getOtherResources = function() {
                return this.otherResources.clone().iterator();
            }

            /**
             * Returns a string representing this object in the xml format specified by the component.xsd schema
             *
             * @param prepend {String} a string to be prepended to each line of the returned XML (useful for indenting)
             *
             * @returns {String} this Resources object as XML, as specified by the component.xsd schema
             */
            config.prototype.toString = function(prepend) {
                if (!prepend) {
                    prepend = "";
                }
                var ret = prepend + "<resources>\n";
                if (this.UIResources.size() > 0) {
                    ret += prepend + "   <ui_resources>\n";
                    var iter = this.UIResources.iterator();
                    while (iter.hasNext()) {
                        ret += iter.next().toString(prepend + "      ");
                    }
                    ret += prepend + "   </ui_resources>\n";
                }
                if (this.otherResources.size() > 0) {
                    ret += prepend + "   <other_resources>\n";
                    var iter = this.otherResources.iterator();
                    while (iter.hasNext()) {
                        ret += iter.next().toString(prepend + "      ");
                    }
                    ret += prepend + "   </other_resources>\n";
                }
                ret += prepend + "</resources>\n";
                return ret;
            }
        }
        );